<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>月度报表</title>
</head>
<body>
<script src="js/echarts.js"></script>
<script src="js/axios-0.18.0.js"></script>

<div id="div" style="width: 100%;height: 400px ;margin: 0 auto">

</div>

<script>
    // 初始化一个图表对象
    let myecharts = echarts.init(document.getElementById("div"));
    // 准备数据
    let option = {
        title: {
            text: '月度报表'
        },
        tooltip: {},
        xAxis: {
            data: []
        },
        yAxis: {},
        series: [
            {
                name:'销售金额',
                type: 'bar',
                data: []
            }
        ]
    };
    alert("tishi")
    axios.get('http://localhost:8080/sales/all').then(res=>{
        alert("tishi11")
        //对上面的 option 对象中的  legend的data进行修改,和series的data进行修改
        let dataArray;
        if (Array.isArray(res.data)) {
            dataArray = res.data;
        } else if (typeof res.data === 'object' && res.data.data) {
            dataArray = res.data.data;
        }
        const months = dataArray.map(item => item.mouth);
        const prices = dataArray.map(item => item.amount);
        option.series[0].data = prices;
        option.xAxis.data = months;
        // 将数据填充到图表对象中
        myecharts.setOption(option);
    })
</script>

</body>
</html>